package org.jeecg.modules.yc.web.service.impl;
import org.jeecg.modules.yc.web.entity.PdDevice;
import org.jeecg.modules.yc.web.mapper.PdDeviceMapper;
import org.jeecg.modules.yc.web.service.IPdDeviceService;
import org.jeecg.modules.yc.web.service.IYcCableJointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.util.ObjectUtils;

/**
 * @Description: 传感器
 * @Author: jeecg-boot
 * @Date:   2024-01-08
 * @Version: V1.0
 */
@Service
public class PdDeviceServiceImpl extends ServiceImpl<PdDeviceMapper, PdDevice> implements IPdDeviceService {

    @Autowired
    private PdDeviceMapper pdDeviceMapper;

    @Autowired
    private IYcCableJointService ycCableJointService;

    @Override
    public Integer deviceCountByTerminalId(String terminalId) {
        return pdDeviceMapper.deviceCountByTerminalId(terminalId);
    }

    @Override
    public boolean updateById(PdDevice pdDevice){
        String cableJointId = pdDevice.getCableJointId();
        if(!ObjectUtils.isEmpty(cableJointId)){
            pdDevice.setLineId(ycCableJointService.getById(cableJointId).getLineId());
        }
        return super.updateById(pdDevice);
    }

    @Override
    public boolean save(PdDevice pdDevice){
        String cableJointId = pdDevice.getCableJointId();
        if(!ObjectUtils.isEmpty(cableJointId)){
            pdDevice.setLineId(ycCableJointService.getById(cableJointId).getLineId());
        }
        return super.save(pdDevice);
    }
}
